package cn.wolfcode.web.controller;

import cn.wolfcode.qo.JsonResult;
import cn.wolfcode.domain.Permission;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    private IPermissionService permissionService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo")QueryObject qo){
        model.addAttribute("pageResult",permissionService.query(qo));
        return "permission/list";//找视图
    }
    @RequestMapping("/delete")
    public String delete(Long id){
        if(id != null){
            permissionService.deleteByPrimaryKey(id);
            }
            return "redirect:/permission/list.do";
    }
    @RequestMapping("/input")
    public String input(Long id,Model model){
        if(id != null){
            Permission permission = permissionService.selectByPrimaryKey(id);
            model.addAttribute("permission",permission);
        }
        return "permission/input";
    }
    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(Permission permission){
        if(permission.getId()!=null){
            permissionService.updateByPrimaryKey(permission);
        }else{
            permissionService.insert(permission);
        }
        return "redirect:/permission/list.do";
    }
    @ResponseBody
    @RequestMapping("/reload")
   public JsonResult reload(){
            permissionService.reload();
            return new JsonResult();
   }

}
